package com.mihuspring.www.context;

import java.util.HashSet;
import java.util.Set;

public class ClassContext {
  private Set<Class<?>> classSet;
  public ClassContext(String packageName){
    try{
      this.classSet = ClassUtils.getClassSet(packageName);
    }catch (Exception err){
      throw new RuntimeException(err);
    }
  }
  public Set<Class<?>> listClass(ClassFilter... classFilterList){
    if(classFilterList.length == 0){
      return classSet;
    }
    Set<Class<?>> filterClassSet = new HashSet<>();
    for(Class<?> cla : classSet){
      for(ClassFilter classFilter : classFilterList){
        if(!classFilter.accept(cla)){
          break;
        }
        filterClassSet.add(cla);
      }
    }
    return filterClassSet;
  }
}
